//@charset "utf-8"
var reloadDelN = false;
var NewNumber = 0;
/*显示我的预警结果*/
String.prototype.replaceAll = function(strFrom, strTo){
	return this.replace(new RegExp(strFrom, 'gm'), strTo);
};
//TabClick 实现tab切换刷新当前页面
var TabClick0 = getUrlParam('TabClick');
var TabClicks = 0;
//alert(location.href);
var taburl = window.location.href.replaceAll('#','');
var value = taburl.match(new RegExp("[\?\&]TabClicks=([^\&]*)(\&?)", "i"));
var tabC= value ? value[1] : value;
$(function(){
//获取f5刷新
document.onkeydown = function (e) {
    var ev = window.event || e;
    var code = ev.keyCode || ev.which;
    if (code == 116) {
        /*var UrlCurrent = window.location.href.split('?');
        var urls = UrlCurrent[0] + '?TabClicks=' + TabClicks;
        //alert(urls);
        window.location.href = urls;*/
        event.keyCode = 0;
        event.cancelBubble = true;
        return false;
    }
};

function isInteger(obj) {
 return obj%1 === 0
}

    //窗口大小
    var clientInterface = new ComClientInterface();
    var txtstr = clientInterface.getFileContent('gpyj.txt');
    var heightnew;
    if (txtstr === false){
        clientInterface.modifyWindowsSize('652','399','Center');
    } else {
		if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
			clientInterface.modifyWindowsSize('652',txtstr+61,'Center');
            heightnew = parseFloat(txtstr);
            $('.pro-table').css('height',heightnew-76);
            $('.pro-result-list, .my-pro-list').css('height',heightnew-48);
		}else {
			clientInterface.modifyWindowsSize('652',txtstr+33,'Center');
            heightnew = parseFloat(txtstr);
            $('.pro-table').css('height',heightnew-106);
            $('.pro-result-list, .my-pro-list').css('height',heightnew-76);
		}
        $('.pro-text-null, .pro-result-null').css('height',heightnew-76);
        $('.pro-text-null p, .pro-result-null p').css('padding-top',heightnew-240);

    }


	subscribeDataStr = clientInterface.getSubData();
    /*var subscribeDataStr = '[{"appname":"","buildtime":"1428479271","datainfo":{"mode":"0,0,0,0,,0","stockcode":"150178","stockname":"证保B","templates":"j","type":"","userid":"114480318","value":"1074334166@0.0000000001"},"lasttime":"0;0;0;0;","mobileid":"","pcid":"0aaf48ad628442959d48b5897f96922f","platform":""},{"appname":"","buildtime":"1428479377","datainfo":{"mode":"0,0,0,1,,0","stockcode":"150178","stockname":"证保B","templates":"j","type":"","userid":"114480318","value":"1074072022@2.0000000001"},"lasttime":"0;0;0;0;","mobileid":"","pcid":"add9ba93c8724d7fa9f57f417c1447ee","platform":""}]';
*/
    //alert(subscribeDataStr);
    var data;
    var dataCF = new Array();
    if(subscribeDataStr == null || subscribeDataStr.length == 0){
        $("#proTableMy").hide();
        $(".pro-text-null").show();
        $(".listli0 i").css('visibility','hidden');

    }else{
        //数组翻转reverse()
        var subscribeData = eval("data=" + subscribeDataStr).reverse();
        var nScrollHights = 0; //滚动距离总长(注意不是滚动条的长度)
        var nScrollTops = 0;   //滚动到的当前位置
        var nDivHights = $("#proTableMy").height();
        //alert(nDivHights);
        var x = 0;
        if(subscribeData.length > 10){

            var subarr = subscribeData.slice(x*10, (x+1)*10);
            var length = subarr.length;
            renderD(length,subarr);
            if(nDivHights > 300){
            
                setInterval(function(){
                    if(nScrollTops + nDivHights >= nScrollHights){
                        x = x+1;
                        var subarr = subscribeData.slice(x*10, (x+1)*10);
                        var length = subarr.length;
                        renderD(length,subarr);
                    }
                  
                },'1000');
            } else {
                $("#proTableMy").scroll(function(){
                    nScrollHights = $(this)[0].scrollHeight;
                    nScrollTops = $(this)[0].scrollTop;
                    
                    if(nScrollTops + nDivHights >= nScrollHights){
                        
                        x = x+1;
                        var subarr = subscribeData.slice(x*10, (x+1)*10);
                        var length = subarr.length;
                        renderD(length,subarr);
                    }
                });
            }
        }else{
            var length = subscribeData.length;
            renderD(length,subscribeData);
        }
        
        
        
    }
function renderD(length,subarr){ 
    if(length != 0){
        $(".pro-text-null").hide();
        $(".listli0 i").css('visibility','visible');
        for (var i = 0; i < length; i ++) {
            var codeh = subarr[i]['datainfo']['stockcode'];
            var codev = subarr[i]['datainfo']['value'];
            var modes = subarr[i]['datainfo']['mode'];
            var market = subarr[i]['datainfo']['market'];
            var temp = subarr[i]['datainfo']['templates'];
            var aaa = subarr[i]['datainfo']['comment'];
            var arrmode = subarr[i]['datainfo']['mode'].split(",");
            //var arrmode = [0,1,0,0,'alert',0];
            var alerts;
            if(arrmode[4] == 'alert'){
                alerts = '警报';
            }
            if(arrmode[4] == 'up'){
                alerts = '向上';
            }
            if(arrmode[4] == '清脆'){
                alerts = '清脆';
            }
            var state;
            var stateid;
            var arrmodes = new Array();
           // mode.push($("#keep_monitor").hasClass("c-on") ? 1 : 0);
            arrmodes.push(arrmode[0] == 0 ? '' : '持续监控');
            arrmodes.push(arrmode[1] == 0 ? '' : '弹框');
            arrmodes.push(arrmode[2] == 0 ? '' : alerts);
            //COCO新增集合竞价
            arrmodes.push(arrmode[6] == 0 ? '' : '集合竞价');

            if(temp == 'j'){
                arrmodes.push(arrmode[5] == 1 ? '' : '');
                if(arrmode[0] == 0 && arrmode[1] == 0 && arrmode[2] == 0 && arrmode[6] == 0 && arrmode[5] == 1){
                    arrmodes = '--';
                }else{
                    arrmodes = $.grep(arrmodes, function(n){return $.trim(n).length > 0;});
                    arrmodes = arrmodes.join('+');
                }
            }else{
                arrmodes.push(arrmode[5] == 1 ? '手机程序': '' );
                if(arrmode[0] == 0 && arrmode[1] == 0 && arrmode[2] == 0 && arrmode[6] == 0 && arrmode[5] == 0){
                    arrmodes = '--';
                }else{
                    arrmodes = $.grep(arrmodes, function(n){return $.trim(n).length > 0;});
                    arrmodes = arrmodes.join('+');
                }
            }

            if(arrmode[3] == 0){
                state = '已关闭';
                stateid = 0;
            }else if(arrmode[3] == 1){
                state = '运行中';
                stateid = 1;
            }
            
            $("#proTableMy table").append('<tr class="Y_bg" pcid="'+ subarr[i]['pcid'] +'" mobileid="'+ subarr[i]['mobileid'] +'" buildtime="'+ subarr[i]['buildtime'] +'" Key="'+i+'" stockcode="'+ subarr[i]['datainfo']['stockcode'] +'" market="'+ subarr[i]['datainfo']['market'] +'" templates="'+ subarr[i]['datainfo']['templates'] +'" value="'+ subarr[i]['datainfo']['value'] +'" arrmode = "'+subarr[i]['datainfo']['mode']+'" modehtml = "'+arrmodes+'" stockname = "'+subarr[i]['datainfo']['stockname']+'"  state="'+stateid+'"><td><i class="btn"></i>' + subarr[i]['datainfo']['stockcode'] + mCutStr(subarr[i]['datainfo']['stockname'],12,'..') +'</td><td>'+ aaa +'</td><td class="tdl-c">' +mCutStr(arrmodes,19,'.')+ '</td><td class="state">'+state+'</td><td><a href="###" class="g-revise">修改</a><a href="###" class="g-delete">删除</a></td></tr><tr class="F_bg" pcid="'+ subarr[i]['pcid'] +'" mobileid="'+ subarr[i]['mobileid'] +'" buildtime="'+ subarr[i]['buildtime'] +'" templates="'+ subarr[i]['datainfo']['templates'] +'"><td>&nbsp;</td><td><div class="Tip_wrap"><i class="Tip_c c-on"></i><input type="text" param = "'+ subarr[i]['datainfo']['templates'] +'" onkeyup="clearNoNum(this)" maxlength="7" class="yj_price" vals = "'+subarr[i]['datainfo']['value']+'" value="'+subarr[i]['datainfo']['value']+'" /><em class="list_tips" view_valid_msg=""></em></div></td><td class="tdl-c"><span class="yj_mode" arrmode_m= "'+ subarr[i]['datainfo']['mode'] +'"></span></td><td colspan="2" class="tdl-l save-r"><a href="###" class="btn yj_save">完成</a><a href="###" class="btn yj_cancel">取消</a></td></tr>');
       }
       $("#proTableMy table tr").eq(0).addClass("tr-click");
           checkBox();
    }
} 



    var num = 1;
    var pages = 10;
    var utils = external.createObject("Util");
    var readWs = clientInterface.getAlertResultCount();
    // alert(readWs + 'a');
    var M = readWs - pages;
    var N = readWs;
    var YM = isInteger(readWs/pages);
    var subresultDataStr = utils.getAlertResult({
        'start': M,
        'end':N
    });
    var readWAll = utils.getAlertResult();
    // alert('all'+readWAll);
    // alert('sss' + subresultDataStr);
    // alert(readWAll);
    var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度)
    var nScrollTop = 0;   //滚动到的当前位置
    var nDivHight = $("#proTableResult").height();
    if(nDivHight > 300){
        setInterval(function(){
            var j = 10;
            if(nScrollTop + nDivHight >= nScrollHight){
                j = j+1;
                num = num+j;
                if (num >= 12 && num < 13) {
                    num = num - 1;
                }
                if(N > 9){
                    M = M - pages - 1;
                    N = N - pages - 1;
                    var subresultDataStr = utils.getAlertResult({
                        'start': M,
                        'end':N
                    })
                    var subresultData = eval('data=' + subresultDataStr);
                    ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
                }
            }
        /*num = num+pages;
            if((M - pages) > 0){
                M = M - pages - 1;
                N = M + pages;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }else if(YM == false){
                var S = M;
                M = 0;
                N = S - 1;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                num = num + 1;
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }else if(M > 0){
                var S = M;
                M = 0;
                N = S - 1;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }*/
    },'1000');
    } else {
        $("#proTableResult").scroll(function(){
        nScrollHight = $(this)[0].scrollHeight;
        nScrollTop = $(this)[0].scrollTop;
        var j = 10;
        if(nScrollTop + nDivHight >= nScrollHight){
            j = j+1;
            num = num+j;
            if (num >= 12 && num < 13) {
                num = num - 1;
            }
            if(N > 9){
                M = M - pages - 1;
                N = N - pages - 1;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }
           /* num = num+pages;
            if((M - pages) > 0){
                M = M - pages - 1;
                N = M + pages;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }else if(YM == false){
                var S = M;
                M = 0;
                N = S - 1;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                num = num + 1;
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }else if(M > 0){
                var S = M;
                M = 0;
                N = S - 1;
                var subresultDataStr = utils.getAlertResult({
                    'start': M,
                    'end':N
                })
                var subresultData = eval('data=' + subresultDataStr);
                ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
            }*/
        }
    });
    }



    if( readWAll == null || readWAll.length == 0){
        $("#proTableResult").hide();
        $(".pro-result-null").show();
        $(".read-all").css("cursor","default");
        $(".look-pro-on").show();
        $(".look-pro").hide();
    }else{
        $(".read-all").css("cursor","pointer");
        $(".look-pro-on").hide();
        $(".look-pro").show();
        var subresultData = eval('data=' + subresultDataStr);
        var readW = 0;
        var readNumber = eval('data=' + readWAll);
        for(var j=0; j<readNumber.length; j++){
            if(readNumber[j]['read'] == 0 ){
                readW ++;
            }
        }
        if(readW > 99){
            $("#proResult i").show();
            $("#proResult i").html('99');
            proResult();
        }else if(readW == 0){
            proMySo();
            $("#proResult i").hide();
        }else{
            proResult();
            $("#proResult i").show();
            $("#proResult i").html(readW);
        }
        $(".pro-result-null").hide();
        $("#proTableResult").show();
        ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num);
        $("#proTableResult table tr").eq(0).addClass("tr-click");
    }
});

function proMySo(){
    $("#proMySo").addClass("tab-on").siblings("a").removeClass("tab-on");
    $(".e-warning").eq($("#proMySo").index()).show().siblings(".e-warning").hide();
    $(".ft-warning").eq($("#proMySo").index()).show().siblings(".ft-warning").hide();
}
function proResult(){
    $("#proResult").addClass("tab-on").siblings("a").removeClass("tab-on");
    $(".e-warning").eq($("#proResult").index()).show().siblings(".e-warning").hide();
    $(".ft-warning").eq($("#proResult").index()).show().siblings(".ft-warning").hide();
}

function checkBox(){
    if($('#proTableMy .Y_bg i').hasClass('c-on')){
        $(".delete-pro").show();
        $(".delete-pro-on").hide();
        $(".off-pro-on").hide();
    }else{
        $(".delete-pro").hide();
        $(".delete-pro-on").show();
        $(".off-pro-on").show();
        $("#on_proset").hide();
        $("#off_proset").hide();
    }
}
//每次加载结果的M-N行
function ListResultData(M,N,subresultData,tabC,TabClicks,TabClick0,num){
    for (var i = 0; i < N-M+1; i ++) {
        var timeX = userDate(subresultData[i]['time']);
        var molld = subresultData[i]['templates'];
        var market =  subresultData[i]['market'] || 120;
        var molds;
        if(molld == "g"){
            molds = "公告类";
        }else if(molld == "l"){
            molds = "问财类";
        }else{
            molds = "股价类";
        }
        $("#proTableResult table").append('<tr class="Y_bg" market="'+market+'" read = "'+subresultData[i]['read']+'" addr="'+subresultData[i]['addr']+'" stockcode="'+subresultData[i]['code']+'" mobileid="'+subresultData[i]['mobileid']+'" pcid="'+subresultData[i]['pcid']+'" url="'+subresultData[i]['url']+'" templates = "'+subresultData[i]['templates']+'"><td>'+(i+num)+'.'+mCutStr(subresultData[i]['code']+subresultData[i]['name'],14,'..')+'</td><td class="mold">'+molds+'</td><td class="recontent">'+mCutStr(subresultData[i]['content'],25,'...')+'</td><td class="tdl-l reprice">'+subresultData[i]['price']+'</td><td class="tdl-c">'+timeX+'</td><td><span class="small-icon bg-buy hide">买</span><span class="small-icon bg-sell hide">卖</span></td></tr>');
        if(subresultData[i]['read'] == 0){
            //url后面参数是1就是预警结果
            proResult();
            $("#proTableResult table tr").last().addClass("tdblod");
            $("#proTableResult table tr").eq(0).addClass("tr-click");
            if( tabC == 1){
                proResult();
                TabClicks = 1;
            }
            if( tabC == 0){
                proMySo();
                TabClicks = 0;
            }

        }else{
            $("#proTableResult table tr").eq(0).addClass("tr-click");
            if( tabC == 1){
                proResult();
                TabClicks = 1;
            }

        }
    }
}


/*全选框*/
$('.listli0 i').live('click',function(){
    var check_on = $(this).parent().find(".c-on");
    var allcheck = $('#proTableMy .Y_bg i');
    var state = [];
    var checkedStr = [];
    if(check_on.css("display") != "inline-block"){
        $(this).addClass("c-on");
        $(".delete-pro").show();
        $(".delete-pro-on").hide();
        allcheck.each(function(i){
            state.push($(this).parent().parent().attr("state"));
            $(this).addClass('c-on');
        });
        checkedStr = state.join(',');
    }else{
        $(this).removeClass("c-on");
        allcheck.each(function(i){
            $(this).removeClass('c-on');
        });
        if ($(this).hasClass('c-on') == false) {
            $(".off-pro-on").show();
            $("#on_proset").hide();
            $("#off_proset").hide();
            $(".delete-pro").hide();
            $(".delete-pro-on").show();
        }
    }
    if (checkedStr.indexOf("1")>=0) {
        $(".off-pro-on").hide();
        $("#on_proset").hide();
        $("#off_proset").show();
    }else {
        $(".off-pro-on").hide();
        $("#on_proset").show();
        $("#off_proset").hide();
    }
});
/*复选框单个选择*/
$('#proTableMy .Y_bg i').live('click',function(){

    var check_on = $(this).parent().find(".c-on");
    var hasCheck = $(this).parent().parent().siblings(".Y_bg").find(".c-on");
    var allcheck = $('.listli0 i');
    var obj = $('#proTableMy .Y_bg i');
    var count = obj.length;
    var selectCount = 0;
    var state = [];
    var checkedStr = [];
    var checked;
    if(check_on.css("display") != "inline-block"){
        $(this).addClass("c-on");
        $(".delete-pro").show();
        $(".delete-pro-on").hide();
        checked = $(".Y_bg .c-on").parent().parent();
    }else{
        $(this).removeClass("c-on");
        checked = $(".Y_bg .c-on").parent().parent();
        if ($(this).hasClass('c-on') == false) {
            $(".off-pro-on").show();
            $("#on_proset").hide();
            $("#off_proset").hide();
        }
    }

    checked.each(function(){
        state.push($(this).attr("state"));
        selectCount++;
    });
    checkedStr = state.join(',');
    if (checkedStr.indexOf("1")>=0) {
        $(".off-pro-on").hide();
        $("#on_proset").hide();
        $("#off_proset").show();
    } else {
        $(".off-pro-on").hide();
        $("#on_proset").show();
        $("#off_proset").hide();
    }
    if(count == selectCount) {
        allcheck.addClass('c-on');
    } else {
        allcheck.removeClass('c-on');
    }
    if(hasCheck.css("display") != "inline-block" && check_on.css("display") == "inline-block"){
        $(".delete-pro").hide();
        $(".delete-pro-on").show();
        $(".off-pro-on").show();
        $("#on_proset").hide();
        $("#off_proset").hide();
    }
});
/*表格tr背景色*/
$(".pro-table").on('mouseover', '.Y_bg', function(){
    var templates = $(this).attr('templates');
    if(templates == 'g'){
        $(this).find(".set").hide();
    }else{
        $(this).find(".set").show();
    }
    $(this).addClass("tr-hover");
}).on('mouseout','tr',function(){
    $(this).find(".set").hide();
    $(this).removeClass("tr-hover");
});
var TimeFn = null;
//我的预警单击
$("#proTableMy").on('click', '.Y_bg',function(){
    $(this).addClass("tr-click").siblings("tr").removeClass("tr-click");
    clearTimeout(TimeFn);
    TimeFn = setTimeout(function(){
    },300);
});
//预警结果手动刷新
$(".refresh").click(function(){
    var isIE=!!window.ActiveXObject;
    var isIE6=isIE&&!window.XMLHttpRequest;
    TaNumber.refreshId();
    if(isIE6){
        var UrlCurrent = window.location.href.split('?');
        var urls = UrlCurrent[0] + '?TabClicks=1';
        location.href = urls;
        window.location.reload();
    }else{
        var UrlCurrent = window.location.href.split('?');
        var urls = UrlCurrent[0] + '?TabClicks=1';
        location.href = urls;
    }
});

//预警结果单击
$("#proTableResult").on('click', '.Y_bg',function(e){
    e = e || window.event;
    if($(e.target).hasClass('bg-buy')){
        jumpBuy(e,0);
        return;
    }else if($(e.target).hasClass('bg-sell')){
        jumpBuy(e,1);
        return;
    }
    TabClick = 1;
    var templates = $(this).attr('templates');
    if(templates == 'g'){
        $(this).find(".set").hide().parent().parent().siblings("tr").find(".set").hide();
    }else{
        $(this).find(".set").show().parent().parent().siblings("tr").find(".set").hide();
    }
    $(this).addClass("tr-click").siblings("tr").removeClass("tr-click");
    var that = this;
    $(".pro-table").on('mouseout', 'tr', function(){
        if(templates == 'g'){
            $(that).find(".set").hide().parent().parent().siblings("tr").find(".set").hide();
        }else{
            $(that).find(".set").show().parent().parent().siblings("tr").find(".set").hide();
        }
    });
    var length = $("#proResult i").html();
    var addr = $(this).attr("addr");
    var hasBlod = $(this).hasClass('tdblod');
    if(hasBlod){
        $("#proResult i").html(length-1);
        $(this).removeClass("tdblod");
        var clientInterface = new ComClientInterface();
            clientInterface.setAlertResultRead(addr);
    }
    if($("#proResult i").html() == 0){
        $("#proResult i").hide();
    }
    clearTimeout(TimeFn);
    TimeFn = setTimeout(function(){
    },300);
});
//我的预警双击
$("#proTableMy").on('dblclick','.Y_bg', function(){
    $(this).addClass("tr-click").siblings("tr").removeClass("tr-click");
    clearTimeout(TimeFn);
    var stockcode = $(this).attr('stockcode');
    var market = $(this).attr('market');
    var mStock = stockcode + '|0|0|' + market;
    url = "hxa://hexin.exe 'opt=13&param=" + mStock + "'";
    location.href = url;
});
//预警结果双击
$("#proTableResult").on('dblclick','.Y_bg', function(){
    TabClick = 1;
    var quote = external.createObject('Quote');
    $(this).addClass("tr-click").siblings("tr").removeClass("tr-click");
    var addr = $(this).attr("addr");
    var length = $("#proResult i").html();
    var hasBlod = $(this).hasClass('tdblod');
    var clientInterface = new ComClientInterface();
    if(hasBlod){
        $("#proResult i").html(length-1);
        $(this).removeClass("tdblod");
       // var clientInterface = new ComClientInterface();
        clientInterface.setAlertResultRead(addr);
    }
    if($("#proResult i").html() == 0){
        $("#proResult i").hide();
    }

    var stockcode = $("#proTableResult table").find(".tr-click").attr('stockcode');
    var templates = $("#proTableResult table").find(".tr-click").attr('templates');
    var pcid = $("#proTableResult table").find(".tr-click").attr('pcid');
    var urlstr = $("#proTableResult table").find(".tr-click").attr('url');
    if (templates == 'g') {
        if(urlstr == '#'){
            url = "hxa://hexin.exe 'opt=13&param=" + stockcode + "'";
            location.href = url;
            quote.actionCommand(31502);//财报发布
        }else{
            clientInterface.openURL(urlstr);//其他公告
        }
    }else if(templates == "l"){
        clientInterface.openURL(urlstr, 6);
        //clientInterface.ShowDetailWebDlg(urlstr);
        //window.open = urlstr;
    }else{
        url = "hxa://hexin.exe 'opt=13&param=" + stockcode + "'";
        location.href = url;
    }
    clearTimeout(TimeFn);
});

/*我的预警和预警结果切换*/
$(".pro-tab a").click(function(){
    $(this).addClass("tab-on").siblings("a").removeClass("tab-on");
    $(".e-warning").eq($(this).index()).show().siblings(".e-warning").hide();
    $(".ft-warning").eq($(this).index()).show().siblings(".ft-warning").hide();
});
//tab中的我的预警
$("#proMySo").click(function(){
    TaNumber.proMySo();
    if(TabClicks == 0){
        return false;
    }else{
        $("#proResult i").hide();
        TabClicks = 0;
    }

});
//tab中预警结果
$("#proResult").click(function(){
    var isIE=!!window.ActiveXObject;
    var isIE6=isIE&&!window.XMLHttpRequest;
    TaNumber.proResult();
    if(TabClicks == 1 || NewNumber == 0){
        return false;
    }else{
        TabClicks = 1;
        if(isIE6){
            var UrlCurrent = window.location.href.split('?');
            var urls = UrlCurrent[0] + '?TabClicks=1';
            location.href = urls;
            window.location.reload();
        }else{
            var UrlCurrent = window.location.href.split('?');
            var urls = UrlCurrent[0] + '?TabClicks=1';
            location.href = urls;
        }

    }
});


/*点击清空列表后面下拉菜单出来*/
//var flag = true;
$(".plate-up").live('click',function(){
    $(".plate-list").css('position','absolute');
    $(".plate-list").show();
    $(".plate-down").show();
    $(".plate-up").hide();
});
$(".plate-down").live('click',function(){
    $(".plate-list").css('position','static');
    $(".plate-list").hide();
    $(".plate-up").show();
    $(".plate-down").hide();
});
$(document).click(function (e) {
	var target = $(e.target);
	if (target.closest('.plate-up').length == 0
		&& target.closest('.plate').length == 0) {
		$(".plate-list").css('display','none');
        $(".plate-list").css('position','static');
        $(".import-list").hide();
        $(".plate-up").show();
        $(".plate-down").hide();
        flag = true;
	}
});
$('.plate').focus(function () {
	this.blur();
	//$(".plate-up").click();
});

/*导出文件*/
//export 和 import-list是否失去焦点
var exportFlag = false;
var importFlag = false;
var isHideImport = function () {
	setTimeout(function () {
		if (importFlag != exportFlag) {
		    $(".import-list").hide();
		}
	}, 50);
}
/**
 * 组合导出格式
 * @param string formatType 格式，excel|text
 */
var tableTh = ['预警品种','预警类型','预警内容', '价格', '预警时间'];
var assembleText = function (formatType) {
	formatType = formatType || 'excel';
	var trObj = $("#proTableResult table tr"),
		//分隔符、换行符
		delimiter = formatType == 'text' ? '\t' : '\t',
		newline	= formatType == 'text' ? '\r\n' : '\r\n',
		returnText = tableTh.join(delimiter) + newline,
		trArr = new Array();

	trObj.each(function (i, tr) {
		var tdArr = new Array();
        $(tr).find('td').each(function (i, td) {
        	if (i < tableTh.length) {
            	tdArr.push($(td).html().replace(/<[^>]+>/g, ''));
        	}
        });
        trArr.push(tdArr.join(delimiter));
    });
	returnText += trArr.join(newline);
    //alert(returnText);
	return returnText;
}
$(".export").mouseover(function(){
	exportFlag = false;
	importFlag = false;
    $(".import-list").show();
});
$(".export").mouseleave(function () {
	exportFlag = true;
	isHideImport();
});
$(".import-list").mouseover(function(){
	exportFlag = false;
	importFlag = false;
});
$(".import-list").mouseleave(function () {
	importFlag = true;
	isHideImport();
});
$("#exportExcel").click(function () {
    TaNumber.exportRe();
	var text = assembleText('excel');
	//接口
	var clientInterface = new ComClientInterface();
	clientInterface.exportSubContent(0, text);
});
$("#exportText").click(function () {
    TaNumber.exportRe();
	var text = assembleText('text');
	//接口
	var clientInterface = new ComClientInterface();
	clientInterface.exportSubContent(1, text);
});
$("#exportToBoard").click(function () {
    TaNumber.exportRe();
	var text = assembleText('text');
//	window.clipboardData.setData('Text', text);
	//接口
	var clientInterface = new ComClientInterface();
	clientInterface.exportSubContent(2, text);
});

//排序部分
/**
 * 排序方法
 * @param obj domObj 要排序的table对象
 * @param string sortType 排序的字段(时间max)，'stockcode|time'
 */
var operaTable = function (tableObj, sortType, sort) {
	sortType = sortType || 'pcid';
	//获取tbody下的tr
	var tbBodyTr 		= $(tableObj).children('tbody').find('tr'),
		tbBodyTrLenght	= tbBodyTr.length,
		isTrue = false,
		tmp1,
		tmp2;
	for (var i = 0; i < tbBodyTrLenght - 2; i+=2 ) {
		for (var k = i + 2; k < tbBodyTrLenght + 2; k+=2) {
			var kValue1 = $(tbBodyTr[i]).attr(sortType),
				kValue2 = $(tbBodyTr[k]).attr(sortType);
			isTrue = sort == 'asc' ? parseFloat(kValue1) > parseFloat(kValue2) :  parseFloat(kValue1) < parseFloat(kValue2);
			if (isTrue) {
                var a=$(tbBodyTr[i]);
                var b=$(tbBodyTr[i + 2]);
                $(a).replaceWith($(b));
                $(b).next().after($(a));
                var a=$(tbBodyTr[i + 1]);
                var b=$(tbBodyTr[i + 3]);
                $(a).replaceWith($(b));
                $(b).next().after($(a));
			}
		}
	}
};
$(".sort0, .sort1").click(function (e) {
	var target = $(e.target);
	var tableObj = $(this).parent().parent().siblings('div').find('table');
    //排序方式
	var sortType = '';
    var sort = 'desc';
	if (target.closest('.sort0').length > 0) {
		sortType = 'Key';
        sort = 'asc';
	} else if (target.closest('.sort1').length > 0) {
		sortType = 'Key';
        sort = 'desc';
	} else {
		return ;
	}
	$(this).siblings('a').show();
	$(this).hide();
	operaTable(tableObj, sortType, sort);
});
/**
 * COCO预警状态排序
 * @authtor yinkeke@myhexin.com
 * @addTime 2017年05月11日
 * @return {[type]} [description]
 */
var tableSort = function(asc,target){
   
    var $target = target;
    var li = $target.closest('li');
    var tbody = $('#proTableMy').find('tbody:first');
    var tr = tbody.find('tr');
    var trLength = tr.length;
    var index = li.index(); //获得当前是第几个表格
    
    var liArr = [],trObj;
    for(var i = 0,len = trLength; i < len; i++){
       
        trObj = [tr.eq(i),tr.eq(i+1)];
        liArr.push(trObj);
        i ++;
    }
    
     liArr.sort(function(a,b){
        var text1 =  a[0].find('td').eq(index).text();
        var text2 =  b[0].find('td').eq(index).text();
        var x,y;
        if(text1.indexOf('运行中') > -1 ){
          
            x = 1;
        }else if(text1.indexOf('已关闭') > -1){
         
            x = 0;
        }   
       

        if(text2.indexOf('运行中') > -1){
            y = 1;
        }else if(text2.indexOf('已关闭') > -1){
            y = 0;
        }
        
      
        if(asc){
            return x - y;
        }else{
            return y - x;
        }
        
     });
     
     tbody.empty();
     var tpml = '';
     for( i = 0,len = trLength / 2; i < len; i++){
       tpml += liArr[i][0].prop('outerHTML') + liArr[i][1].prop('outerHTML');
     }
     tbody.append(tpml);
        
};
$('.s-bottom, .s-top').click(function(e){
    
    e = e || window.event;
    var asc = false;
    var $target = $(e.target);
    if($target.hasClass('s-bottom')){
        $target.hide();
        $('.s-top').show();
        asc = false;
    }else if($target.hasClass('s-top')){
        $target.hide();
        $('.s-bottom').show();
        asc = true;
    }
   
    //执行排序方法
    tableSort(asc,$target);
});
/*添加预警*/
$(".add-pro").click(function(){
    var pcurStock = external.createObject('Passport');
    var code = pcurStock.curStock();
    var market = pcurStock.getMarketStock('');
    var clientInterface = new ComClientInterface();
    clientInterface.openBrownSetSub(code,market);
    TaNumber.addProset();
});

/*修改预警*/
$("#proTableMy").on('click','tr .g-revise',function(){
    TaNumber.gRevise();
    var stockcode = $(this).parent().parent().attr('stockcode');
	var market = $(this).parent().parent().attr('market');
    var templates = $(this).parent().parent().attr('templates');
    var pcid = $(this).parent().parent().attr('pcid');
    var mobileid = $(this).parent().parent().attr('mobileid');
    var modehtml = $(this).parent().parent().attr('modehtml');
    var clientInterface = new ComClientInterface();
    $('.yj_price').hide();
    $('.yj_price').val($(this).parent().parent().next().find(".Tip_wrap .yj_price").attr('vals'));
    $(".yj_mode").hide();
    $(".list_tips").html('');
    $(".F_bg").hide();
    var mStock = market+ ':' + stockcode;
    try {
        hqQuote.request(condition.renderList, mStock, 'now', stockcode);
    }catch (exp) {
        //alert(exp.message);
    }
    if(templates == 'j' || templates == 'k'){
        //alert(pcid);
        clientInterface.modLocalAlertCfg(pcid);
    }else if(templates == 'g' || templates == 'l'){
        $(this).parent().parent().next().show();
        $(this).parent().parent().next().find('.yj_mode').show();
        $(".yj_mode").html(mCutStr(modehtml,18,'..'));
        condition.bindEvent();
    }else{
        $(this).parent().parent().next().show();
        $(this).parent().parent().next().find('.yj_price').show();
        $(this).parent().parent().next().find('.yj_mode').show();
        $(".yj_mode").html(mCutStr(modehtml,18,'..'));
        var tipC = $(this).parent().parent().next().find(".Tip_wrap .Tip_c");
        var yjPrice = $(this).parent().parent().next().find(".Tip_wrap .yj_price");
        var listTips = $(this).parent().parent().next().find(".Tip_wrap .list_tips");
        yjPrice.attr("view_less_value","");
        yjPrice.attr("view_max_value","");
        listTips.attr("view_empty_msg","条件不可为空");
        listTips.attr("view_less_msg","");
        listTips.attr("view_max_msg","");
        listTips.attr("view_valid_msg","");
        if(templates == 'a'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_price_up");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_price_up_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_price_up_msg");
            tipC.addClass("view_price_up");
            yjPrice.addClass("view_price_up_input");
            listTips.addClass("view_price_up_msg");
            listTips.attr("view_less_msg","不可小于现价");
        }
        if(templates == 'b'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_price_down");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_price_down_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_price_down_msg");
            tipC.addClass("view_price_down");
            yjPrice.addClass("view_price_down_input");
            listTips.addClass("view_price_down_msg");
            listTips.attr("view_max_msg","不可大于现价");
        }
        if(templates == 'c'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_day_zhangfu");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_day_zhangfu_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_day_zhangfu_msg");
            tipC.addClass("view_day_zhangfu");
            yjPrice.addClass("view_day_zhangfu_input");
            listTips.addClass("view_day_zhangfu_msg");
            yjPrice.attr("view_max_value","10.09");
            listTips.attr("view_max_msg","不可大于10%");
        }
        if(templates == 'd'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_day_diefu");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_day_diefu_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_day_diefu_msg");
            tipC.addClass("view_day_diefu");
            yjPrice.addClass("view_day_diefu_input");
            listTips.addClass("view_day_diefu_msg");
            yjPrice.attr("view_max_value","10.09");
            listTips.attr("view_max_msg","不可大于10%");
        }
        if(templates == 'e'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_fivemin_zhangfu");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_fivemin_zhangfu_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_fivemin_zhangfu_msg");
            tipC.addClass("view_fivemin_zhangfu");
            yjPrice.addClass("view_fivemin_zhangfu_input");
            listTips.addClass("view_fivemin_zhangfu_msg");
            yjPrice.attr("view_max_value","22");
            listTips.attr("view_max_msg","不可大于22%");
        }
        if(templates == 'f'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_fivemin_diefu");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_fivemin_diefu_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_fivemin_diefu_msg");
            tipC.addClass("view_fivemin_diefu");
            yjPrice.addClass("view_fivemin_diefu_input");
            listTips.addClass("view_fivemin_diefu_msg");
            yjPrice.attr("view_max_value","22");
            listTips.attr("view_max_msg","不可大于22%");
        }
        if(templates == 'h'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_huanshoulv");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_huanshoulv_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_huanshoulv_msg");
            tipC.addClass("view_huanshoulv");
            yjPrice.addClass("view_huanshoulv_input");
            listTips.addClass("view_huanshoulv_msg");
            yjPrice.attr("view_max_value","100");
            listTips.attr("view_max_msg","不可大于100%");
        }
        if(templates == 'i'){
            $(".F_bg").find(".Tip_wrap .Tip_c").removeClass("view_one_chengjiaoliang");
            $(".F_bg").find(".Tip_wrap .yj_price").removeClass("view_one_chengjiaoliang_input");
            $(".F_bg").find(".Tip_wrap .list_tips").removeClass("view_one_chengjiaoliang_msg");
            tipC.addClass("view_one_chengjiaoliang");
            yjPrice.addClass("view_one_chengjiaoliang_input");
            listTips.addClass("view_one_chengjiaoliang_msg");
        }
        condition.bindEvent();
    }
    var bH = $("#proTableMy").scrollTop();
    var fhtml = $("#proTableMy .Y_bg").last().html();
    var bhtml = $(this).parent().parent().html();
    if(fhtml == bhtml){
        $("#proTableMy").scrollTop($("#proTableMy").scrollTop()+40);
    }
});
//取消修改
$("#proTableMy, #proTableResult").on('click','tr .yj_cancel',function(){
    $('.yj_price').hide();
    $(".yj_mode").hide();
    $(".F_bg").hide();
});
//预警结果里面单行修改设置
/*$("#proTableResult").on('click','tr .set',function(){
    TaNumber.resultSet();

    var stockcode = $(this).parent().parent().attr('stockcode');
    var templates = $(this).parent().parent().attr('templates');
    var pcid = $(this).parent().parent().attr('pcid');
    var clientInterface = new ComClientInterface();

    if(templates == 'j'){
        clientInterface.modLocalAlertCfg(pcid);
    }else{
        //clientInterface.openBrownSetSub(stockcode);
        $(".F_bg").hide();
        $(this).parent().parent().next().show();
        $(this).parent().parent().next().find('.yj_price').show();
    }

});*/

/*删除单行预警my*/
$(".g-delete").live("click",function(){
   reloadDelN = true;
   TaNumber.gDelete();
   var deleteSimgle = [];
   var deleteSimgleM = [];
   var deletesim = $(this).parent().parent().attr('pcid');
   var stockcode = $(this).parent().parent().attr('stockcode');
   var deletesmob = $(this).parent().parent().attr('mobileid');
   var templates = $(this).parent().parent().attr('templates');
   var value = $(this).parent().parent().attr('value');
    var clientInterface = new ComClientInterface();
    subscribeDataStr = clientInterface.getSubData();
    var subscribeData = eval("data=" + subscribeDataStr);
    var length = subscribeData.length;
   if(deletesim != ''){
        deleteSimgle.push('pcid:'+ deletesim);
        var checkedSimStr = deleteSimgle.join(',');
        var del = clientInterface.delsubscribe(checkedSimStr);
        if(del == true){
            $(".kinds_tip").html('删除成功！');
            $(".kinds_tip").fadeIn(500);
            $(this).parent().parent().next().remove();
            $(this).parent().parent().remove();
            //alert($(this).parent().parent().remove());
            clearTimeout(time);
            var time = setTimeout(function(){
                if ($("#proTableMy .Y_bg").length == 0) {
                    $('#proTableMy').hide();
                    $(".pro-text-null").show();
                    $(".listli0 i").css('visibility','hidden');
                }
               $(".kinds_tip").fadeOut(500);
               $("#proTableMy table tr").eq(0).addClass("tr-click");
               checkBox();

            },500);

        }else{
            $(".kinds_tip").html('删除失败！');
            $(".kinds_tip").fadeIn(500);
            clearTimeout(time);
            var time = setTimeout(function(){
               $(".kinds_tip").fadeOut(500);
            },50);
        }

   }
   if(deletesmob != ''){
        deleteSimgleM.push('mobileid:'+ deletesmob);
        var checkedSimStrM = deleteSimgleM.join(',');
        var delM = clientInterface.delsubscribe(checkedSimStrM);
        if(delM == true){
            $(".kinds_tip").html('删除成功！');
            $(".kinds_tip").fadeIn(500);
            $(this).parent().parent().next().remove();
            $(this).parent().parent().remove();
            clearTimeout(time);
            var time = setTimeout(function(){
                if ($("#proTableMy .Y_bg").length == 0) {
                    $('#proTableMy').hide();
                    $(".pro-text-null").show();
                    $(".listli0 i").css('visibility','hidden');
                }
               $(".kinds_tip").fadeOut(500);
               $("#proTableMy table tr").eq(0).addClass("tr-click");
               checkBox();
            },500);

        }else{
            $(".kinds_tip").html('删除失败！');
            $(".kinds_tip").fadeIn(1000);
            clearTimeout(time);
            var time = setTimeout(function(){
               $(".kinds_tip").fadeOut(1000);
            },50);
        }
   }
});

/*删除所选*/

$(".delete-pro").click(function(){
    reloadDelN = true;
    TaNumber.deleteProset();
    var checkeds = [];
    var checkedsM = [];
    var checked = $(".Y_bg .c-on").parent().parent();
    var clientInterface = new ComClientInterface();
    subscribeDataStr = clientInterface.getSubData();
    var subscribeData = eval("data=" + subscribeDataStr);
    var length = subscribeData.length;
    checked.each(function(i){
        if($(this).attr("pcid") !== undefined || $(this).attr("pcid") !== ''){
            checkeds.push('pcid:'+ $(this).attr("pcid"));
        }
        if($(this).attr("mobileid") !== undefined || $(this).attr("mobileid") !== ''){
            checkeds.push('mobileid:'+ $(this).attr("mobileid"));
        }
    });

    if(checked.length == 0){
        alert("没有要删除的预警");
    }else{
        var checkedStr = checkeds.join(',');
    	var del = clientInterface.delsubscribe(checkedStr);
        if(del == true){
            $(".kinds_tip").html('删除成功！');
            $(".kinds_tip").fadeIn(500);
            $(".listli0 i").removeClass('c-on');
            checked.remove();

            //clearTimeout(time);
            var time = setTimeout(function(){
                if ($("#proTableMy .Y_bg").length == 0) {
                    $('#proTableMy').hide();
                    $(".pro-text-null").show();
                    $(".listli0 i").css('visibility','hidden');
                }
                $(".kinds_tip").fadeOut(500);
                $("#proTableMy table tr").eq(0).addClass("tr-click");
                checkBox();

            },500);

        }else{
            $(".kinds_tip").html('删除失败！');
            $(".kinds_tip").fadeIn(500);
            clearTimeout(time);
            var time = setTimeout(function(){
               $(".kinds_tip").fadeOut(500);
            },500);
        }

    }
});
//关闭所选id
$("#off_proset").on('click',function(){
    reloadDelN = true;
    var checked = $(".Y_bg .c-on").parent().parent();
    var checkeds = [];
    checked.each(function(i){
        if($(this).attr("pcid") !== undefined || $(this).attr("pcid") !== ''){
            checkeds.push('pcid:'+ $(this).attr("pcid"));
        }
        if($(this).attr("mobileid") !== undefined || $(this).attr("mobileid") !== ''){
            checkeds.push('mobileid:'+ $(this).attr("mobileid"));
        }
    });
    var checkedStr = checkeds.join(',');
    var clientInterface = new ComClientInterface();
    clientInterface.closeSub(checkedStr);

    checked.each(function(i){
        $(this).find('.state').html('已关闭');
        $(this).attr('state',0);
    });

    $(".off-pro-on").hide();
    $("#on_proset").show();
    $("#off_proset").hide();

    TaNumber.offProset();
});
//开启所选id
$("#on_proset").on('click',function(){
    reloadDelN = true;
    var checked = $(".Y_bg .c-on").parent().parent();
    var checkeds = [];
    checked.each(function(i){
        if($(this).attr("pcid") !== undefined || $(this).attr("pcid") !== ''){
            checkeds.push('pcid:'+ $(this).attr("pcid"));
        }
        if($(this).attr("mobileid") !== undefined || $(this).attr("mobileid") !== ''){
            checkeds.push('mobileid:'+ $(this).attr("mobileid"));
        }
    });
    var checkedStr = checkeds.join(',');
    var clientInterface = new ComClientInterface();
    clientInterface.openSub(checkedStr);
    checked.each(function(i){
        $(this).find('.state').html('运行中');
        $(this).attr('state',1);
    });

     $(".off-pro-on").hide();
    $("#on_proset").hide();
    $("#off_proset").show();
    TaNumber.onProset();
});
//删除某一行结果页下面的删除选中
$("#deleteMh").click(function(){
    TaNumber.deleteMh();
    var deletes = $("#proTableResult table").find(".tr-click").attr("addr");
    var clientInterface = new ComClientInterface();
    var del = clientInterface.moveSubResult(deletes);
    var trlength = $("#proTableResult table tr").length;
    var FB = $("#proTableResult table").find(".tr-click");
    var len = $("#proResult i").html();
    if(del == true){
        $(".kinds_tip").html('删除成功！');
        $(".kinds_tip").fadeIn(500);
        clearTimeout(time);
        var time = setTimeout(function(){
            if(trlength == 1){
              $("#proResult i").hide();
              $("#proResult i").html(0);
            }
            if(FB.hasClass('tdblod')){
                len --;
                $("#proResult i").html(len);
            }
            $("#proTableResult table").find(".tr-click").remove();
            $(".kinds_tip").fadeOut(500);
            $("#proTableResult table tr").eq(0).addClass("tr-click");

        },500);
    }else{
        $(".kinds_tip").html('删除失败！');
        $(".kinds_tip").fadeIn(500);
        clearTimeout(time);
        var time = setTimeout(function(){
           $(".kinds_tip").fadeOut(500);
        },500);
    }
});
/*点击清空列表*/
$(".plate").click(function(){
    var lengths = $("#proTableResult table tr").length;
    if(lengths >0){
        var clientInterface = new ComClientInterface();
        var del = clientInterface.moveSubResult('all');
        if(del == true){
            $(".kinds_tip").html('清空成功！');
            $(".kinds_tip").fadeIn(1000);
            $(".look-pro-on").show();
            $(".look-pro").hide();
            clearTimeout(time);
            var time = setTimeout(function(){
               $("#proTableResult").hide();
               $("#proTableResult table tr").remove();
               $("#proResult i").hide();
               $(".pro-result-null").show();
               $("#proResult i").html(0);
               $(".kinds_tip").fadeOut(1000);
            },500);
             $(".plate-list").hide();
             $(".plate-up").show();
             $(".plate-down").hide();

        }else{
            $(".kinds_tip").html('当前没有预警结果哦！');
            $(".kinds_tip").fadeIn(1000);
            clearTimeout(time);
            var time = setTimeout(function(){
               $(".kinds_tip").fadeOut(1000);
            },500);
        }
       
    }else{
       // $("#plate_null").css("cursor","default");
    }
   
    

   TaNumber.plateNull();

});
/**
 * 已读全部
 */
$('.read-all').click(function(){
    var clientInterface = new ComClientInterface();
    var utils = external.createObject('Util');
    var readWAll = utils.getAlertResult();
    readWAll = eval("("+readWAll+")");
    for(var i = 0, len = readWAll.length; i < len; i ++){
        clientInterface.setAlertResultRead(readWAll[i]['addr']);    
    }
    
    $('#proTableResult').find('tr').removeClass('tdblod');
    $('#proResult').find('.btn').hide();

});
/*查看走势*/
$(".look-pro").click(function(){
	TaNumber.lookProset();
    var stockcode = $("#proTableResult table").find(".tr-click").attr('stockcode');
    var market = $("#proTableResult table").find(".tr-click").attr('market');
    var mStock = stockcode + '|0|0|' + market;
	if (typeof(stockcode) != 'undefined') {
		url = "hxa://hexin.exe 'opt=13&param=" + mStock + "'";
		location.href = url;
	}
});
//加入板块
$("#add_bankuan").click(function(){
    var stockcode = $("#proTableResult table").find(".tr-click").attr('stockcode');
    var clientInterface = new ComClientInterface();
    clientInterface.addCodeToBlock(stockcode);
    TaNumber.addBankuan();
});

//点击预警方式修改
$(".yj_mode").live('click',function(){
    $('.mask').show();
    $(".s-box").show();
    var pcid = $(this).parent().parent().prev().attr('pcid');
    var modestr = $(this).parent().parent().prev().attr('arrmode');
    
    var arrmode_m = modestr.split(",");

    if(modestr != ''){
        if(arrmode_m[0] == 1){
            $("#keep_monitor").addClass("c-on");
        }else{
            $("#keep_monitor").removeClass("c-on");
        }
        if(arrmode_m[1] == 1){
            $("#show_pop").addClass("c-on");
        }else{
            $("#show_pop").removeClass("c-on");
        }
        if(arrmode_m[5] == 1){
            $("#keep_iphone").addClass("c-on");
        }else{
            $("#keep_iphone").removeClass("c-on");
        }

        if(arrmode_m[6] == 1){
            $("#call_auction").addClass("c-on");
        }else{
            $("#call_auction").removeClass("c-on");
        }

        if(arrmode_m[2] == 1){
            if(arrmode_m[4] == 'alert'){
                $("#soundid").find('[value="alert"]').get(0).selected = true;
            }else if(arrmode_m[4] == 'up'){
                $("#soundid").find('[value="up"]').get(0).selected = true;
            }else if(arrmode_m[4] == '清脆'){
                $("#soundid").find('[value="清脆"]').get(0).selected = true;
            }
        }else{
            $("#show_sounds").removeClass("c-on");
            $("#soundid").hide();

        }
    }
});
/*保存预警*/
$(".yj_save").live('click',function(){
    var stockcode = $(this).parent().parent().prev().attr('stockcode');
    var stockname = $(this).parent().parent().prev().attr('stockname');
    var clientInterface = new ComClientInterface({'stockcode':stockcode, 'stockname':stockname});
    var pcid = $(this).parent().parent().prev().attr('pcid');
    var mobileid = $(this).parent().parent().prev().attr('mobileid');
    var market = $(this).parent().parent().prev().attr('market');
    var emMsg = $(this).parent().parent().find('.list_tips');
    var mode = $(this).parent().parent().find(".yj_mode");
    var newvalue = $(this).parent().parent().prev().attr('value');
    mode = mode.attr('arrmode_m');
  
    var pcc = 1;
    var modeay = [];
    var modev = mode.split(",");

    clientInterface.setDefaultAlertMode(mode);
    var shakeI = 0;
    if(pcid != ''){
        if($(emMsg).attr('view_valid_msg') == $(emMsg).html()){
            var paramName = $(emMsg).siblings('input').attr('param');
            var paramValue = $(emMsg).siblings('input').val();
            if(paramValue != newvalue){
                if(modev[3] == 0){
                    modev[3] = 1;
                }
                mode = modev.join(',');

                clientInterface.formatSetSubData(paramName, paramValue, mode,market, pcid);
            }else{
               clientInterface.formatSetSubData(paramName, paramValue, mode,market, pcid);
            }
            clientInterface.postSetSubData(pcc);
        }else if($(emMsg).attr('view_empty_msg') == $(emMsg).html() || $(emMsg).attr('view_less_msg') == $(emMsg).html() || $(emMsg).attr('view_max_msg') == $(emMsg).html()) {
            if(shakeI == 0){
                shake($(emMsg),'shake',1);
                shakeI = 1;
            }
        }
    }else if(mobileid != ''){
        if($(emMsg).attr('view_valid_msg') == $(emMsg).html()){
            var paramName = $(emMsg).siblings('input').attr('param');
            var paramValue = $(emMsg).siblings('input').val();
            if(paramValue != newvalue){
                if(modev[3] == 0){
                    modev[3] = 1;
                }
                mode = modev.join(',');
                
                clientInterface.formatSetSubData(paramName, paramValue, mode,market, pcid, mobileid);
            }else{
                clientInterface.formatSetSubData(paramName, paramValue, mode,market, pcid, mobileid);
            }
            clientInterface.postSetSubData(pcc);
        }else if($(emMsg).attr('view_empty_msg') == $(emMsg).html() || $(emMsg).attr('view_less_msg') == $(emMsg).html() || $(emMsg).attr('view_max_msg') == $(emMsg).html()) {
            if(shakeI == 0){
                shake($(emMsg),'shake',1);
                shakeI = 1;
            }
        }
    }

});
/**
 * @author COCO
 * @addTime 2017-05-11
 * 预警结果鼠标悬浮出现买卖图标
 */
$('#proTableResult').on({'mouseover':function(e){
    toggleClass(e,0);
},'mouseout':function(e){
    toggleClass(e,1);
}});

function toggleClass(e,flag){
    e = e || window.event;
    var $target = $(e.target);
    var $closeTr = $target.closest('tr');
    if(flag){
        $closeTr.find('.small-icon').addClass('hide');
    }else{
        $closeTr.find('.small-icon').removeClass('hide');    
    }
    
}

function jumpBuy(e,flag){
    
    e = e || window.event;
    var $target = $(e.target);
    var $closeTr = $target.closest('tr');
    var code = $closeTr.attr('stockcode');
    var market = $closeTr.attr('market');
    var type = 'NEW';
   
    getRequest(code,type,function(data){
        var newPrice = data[code]['NEW'];
		var passport = external.createObject('Passport');
		var account = passport.get('account');
		var userid = passport.get('userid');
		var strInfo = '<?xml version="1.0" encoding="GB2312">'+
							'<RealTime uid="'+userid+'" StockCode="'+code+'" >'+
								'<Bid>'+
									'<Price Selected="1">'+newPrice+'</Price>'+
                                   // '<Amount>95563</Amount>'+
								'</Bid>'+
							'</RealTime>';
		var util = external.createObject('Util');
		strInfo = 'realtime=' + util.base64Encrypt(strInfo);
		strInfo = 'wt_startup=wt_startup=\r\n' + strInfo;
		var xdMgr = external.createObject('XdMgr');
		var cmd = 'XD_MAIRU';
		if(flag === 1){
			cmd = 'XD_MAICHU';
		}
		xdMgr.fastCallXiadan({'cmd':cmd,'code':code,'info':strInfo,'default':false,'hide':false,'select':false});
    });
}
function getRequest(code,type,callback){
    var quote = external.createObject('Quote');
    var req = {
        code:code,
        type:type,
        onready:function(){
            var ret = {
                code : code,
                type : type
            };
            var data = quote.getData(ret);
            data = eval(data);
            callback(data);
        }
    };
    quote.request(req);
}